package com.csist.jobtitleevaluation.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csist.jobtitleevaluation.exception.ClientParameterException;
import com.csist.jobtitleevaluation.mapper.WtzxMapper;
import com.csist.jobtitleevaluation.po.Wtzx;
import com.csist.jobtitleevaluation.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * <p>
 * 问题咨询 前端控制器
 * </p>
 *
 <<<<<<< HEAD
 * @author zhizhe
 * @since 2021-12-03
=======
 * @author zhizhe
 * @since 2021-12-03
>>>>>>> zhizhe
 */
@RestController
@RequestMapping("/inquiry")
public class WtzxController {



    @Autowired
    private WtzxMapper wtzxMapper;

    /**
     * 查询所有问题咨询
     * @param currentPage  当前页
     * @param isPersonal  是否为个人问题咨询
     * @return
     */
    @GetMapping("/all")
    public Page<Wtzx> queryInquiryAll(@RequestBody Integer userid, Integer currentPage,boolean isPersonal){
        Page<Wtzx> page = new Page<>(currentPage,8);
        QueryWrapper<Wtzx> wrapper = new QueryWrapper<>();
        if (isPersonal){
            wrapper.eq("w_create_user",userid);
        }

        wtzxMapper.selectPage(page, wrapper);

        return page;
    }

    /**
     * 新增提问内容
     * @param center 咨询内容
     */
    @PostMapping("/add")
    public void  insertInquiry(String center){

        if (center==null) throw new ClientParameterException("提问内容不能为空");

        Wtzx wtzx = new Wtzx();
        wtzx.setWTwnr(center);
        wtzxMapper.insert(wtzx);

    }

}
